/*
 * 
 *    _______  _______  _        _______ _________ _______  _______ _________ _______  _______         _______  ______           
 *   (  ____ )(  ____ \( \      (  ___  )\__   __/(  ___  )(  ____ )\__   __/(  ___  )(  ____ \       (  ____ \(  __  \ |\     /|
 *   | (    )|| (    \/| (      | (   ) |   ) (   | (   ) || (    )|   ) (   | (   ) || (    \/       | (    \/| (  \  )| )   ( |
 *   | (____)|| (__    | |      | (___) |   | |   | |   | || (____)|   | |   | |   | || (_____  _____ | (__    | |   ) || |   | |
 *   |     __)|  __)   | |      |  ___  |   | |   | |   | ||     __)   | |   | |   | |(_____  )(_____)|  __)   | |   | || |   | |
 *   | (\ (   | (      | |      | (   ) |   | |   | |   | || (\ (      | |   | |   | |      ) |       | (      | |   ) || |   | |
 *   | ) \ \__| (____/\| (____/\| )   ( |   | |   | (___) || ) \ \_____) (___| (___) |/\____) |       | (____/\| (__/  )| (___) |
 *   |/   \__/(_______/(_______/|/     \|   )_(   (_______)|/   \__/\_______/(_______)\_______)       (_______/(______/ (_______)
 *                                                                                                                  
 *      
 * 
 *      Copyleft (c) 2012 - 2013 Relatórios-EDU
 *
 *      http://ww2.ifro.edu.br/relatorios-edu
 *      DGTI - IFRO (69) - 2182-9623
 *          Alan de Oliveira Silva - alan.oliveira@ifro.edu.br
 *          Bruce F. Reis de Albuquerque - bruce.albuquerque@ifro.edu.br
 *          Flávio Marcos de Moraes - flavio.moraes@ifro.edu.br
 * 
 *      
 * 
 */



package br.org.ccb.ccbadm.connection;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author alanoliveira
 */
public class PersistenceTransaction implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private EntityManager em = null;
    private EntityManagerFactory emf = null;
    
    public PersistenceTransaction() {
        emf = Persistence.createEntityManagerFactory("ccbadmPU");
        em = emf.createEntityManager();

    }
    
    public void begin() {
            em.getTransaction().begin();
    }
    
    public void commit() {
            em.getTransaction().commit();
    }
    
    public void rollback() {
            em.getTransaction().rollback();
       
    }
    
    public EntityManager getEntityManager() {
        return em;
    }
    
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + Objects.hashCode(this.em);
        hash = 97 * hash + Objects.hashCode(this.emf);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PersistenceTransaction other = (PersistenceTransaction) obj;
        if (!Objects.equals(this.em, other.em)) {
            return false;
        }
        if (!Objects.equals(this.emf, other.emf)) {
            return false;
        }
        return true;
    }
    
      
}
